home *** CD-ROM | disk | FTP | other *** search
- > --text.txt look like this--
- > 5
- > 8
- > --------------------
- > R$="text.txt"
- > Open In 1,R$ : A=Lof(1) : Close 1
- > Reserve As Work 16,A : Bload R$,16 : ABC=Start(16)
- > C1=Peek(ABC) : Inc ABC : C2=Peek(ABC)
- > Print C1 : rem gives the ascii value
- > Print Chr$(C1) : show numeral 5
- > ---------------------
- > Ok how will do to make amos to understand that i want to treat this
- > as a number instead of an ascii value?
- > Is there anyway to convert that 5 (53) so
- > i can use it like this:
- > TAL=C1+C2
- > Print TAL : want it to be 13
-
-
- Sure, there is always a way... :-)
-
- -----<CODE BEGINS HERE>-----
- Global GRABVALUE
-
- Procedure GRABDIGITS[MEMLOC, NUMDIGITS]
- GRABVALUE=0
- While NUMDIGITS
- DIGIT=Peek(MEMLOC) : Inc MEMLOC
- ' IF this is really a digit, add it's value to the total...
- If (DIGIT>47 And DIGIT<58)
- Add GRABVALUE, DIGIT-48
- Dec NUMDIGITS
- End If
- Wend
- End Proc
-
- ' Main Code here...
- R$="text.txt"
- Open In 1,R$ : TFSIZE=Lof(1) : Close 1
- Reserve As Work 16, TFSIZE : ABC=Start(16)
- Bload R$, ABC
- GRABDIGITS[ABC, 2] : TAL=GRABVALUE
- Print TAL : Rem ...should be 13
- End
- -----<CODE ENDS HERE>-----
-
- That should do the trick... It won't matter if the digits are seperated
- by commas, spaces, carriage returns, etc. as GRABDIGITS will
- simply skip over non-digits until it has gathered the quantity you
- specified.
-
- Really, this would be better if implemented with a parameter
- returned from the function, but I really don't like the Param
- style AMOS uses, it makes more sense to me to use a GLOBAL
- variable (GRABVALUE in this case)...
-
- Suggestion for AMOS Version 3.0 = Support for "REAL" function
- style procedures, as in:
-
- Print GRABDIGITS(ABC, 2)
- or at least
- TAL=GRABDIGITS(ABC, 2)
-
-
- Garfield Benjamin e-mail:gbenjam@sosbbs.com
- Website( http://www.sosbbs.com/~gbenjam ): 50% Complete
-
-